package com.gack.business.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gack.business.model.BackLog;
import com.gack.business.model.BackUser;
import com.gack.business.repository.BackLogRepsitory;
import com.gack.business.repository.BackUserRepository;

/**
 * 
* @ClassName: BackLogService 
* @Description: TODO(这里用一句话描述这个类的作用) 
* @author (ZhangXinYu)  
* @date 2018年6月14日 上午11:26:22 
* @version V1.0
 */
@Service
public class BackLogService implements BackLogServiceInterface{

	@Autowired
	private BackLogRepsitory backLogRepository;
	@Autowired
	private BackUserRepository backUserRepository;
	
	@Override
	public void addBackLog(String id, String details) {
		BackLog backLog =new BackLog();
		backLog.setOperationdate(new Date());
		backLog.setDetails(details);
		BackUser  backUser=	backUserRepository.findOne(id);
		if(backUser!=null){
			//backLog.setName(backUser.getName());
			backLog.setName(backUser.getUsername());
			if(backUser.getPids().equals("0")&&backUser.getPids()!=null&&!backUser.getPids().equals("")){
				backLog.setStatus("0");
				backLog.setType("后台");
			}else if(backUser.getPids().equals("1")&&backUser.getPids()!=null&&!backUser.getPids().equals("")){
				backLog.setStatus("1");
				backLog.setType("后台");
			}else if(backUser.getPids().equals("2")&&backUser.getPids()!=null&&!backUser.getPids().equals("")){
				backLog.setStatus("2");
				backLog.setType("门店");
			}
		}
		backLogRepository.save(backLog); 
	}

}
